<?php
/**
 * base controller
 * @文件名称: BaseController.php
 * @author: jawei
 * @Email: gaozhiwei@etcp.cn
 * @Date: 2017-06-06
 * @Copyright: 2017 悦畅科技有限公司. All rights reserved.
 * 注意：本内容仅限于悦畅科技有限公司内部传阅，禁止外泄以及用于其他的商业目的
 */
namespace app\controllers;
use app\base\BaseController;
use app\lib\Common;
use app\modules\user\services\user\UserService;
use Yii;

/**
 * 默认路由
 */
class SiteController extends BaseController
{
    /** 禁用layout */
    public $layout = false;
    public function beforeAction($action) {
        $userid = UserService::getUserId();
        $userInfo = [];
        if($userid) {
            $userRet = json_decode(UserService::getUserInfo($userid), true);
            if(isset($userRet['code']) && $userRet['code'] == 0) {
                $userInfo = $userRet['data'];
            }
        }
        $this->userInfo = $userInfo;
        $channel_str = Yii::$app->request->get('channel_str', null);
        if($channel_str) {
            Common::setCookie('channel_str', $channel_str);
        }
        return parent::beforeAction($action);
    }
    /**
     * 前端(单页面应用)入口
     */
    public function actionIndex()
    {
        $rangCode = Common::getRandChar(15);
        $session = Yii::$app->session;
        $session->set('rangCode', $rangCode);
        return $this->render('index',[
            'rangCode' => $rangCode,
            'channelStr' => Common::getCookie('channel_str'),//传递的邀请码
        ]
        );
    }
}
